﻿using System.Collections.Generic;
using UnityEngine;


namespace Super
{
	/// <summary>
	/// 这个类放置需要数据支持的函数
	///	函数数量大于4个，建议搞一个专门的manager管理
	/// </summary>
	public static class DataHelperUtil
	{
		/*********************************不随场景销毁游戏对象字典映射*************************************************/
		private static Dictionary<string, GameObject> dontDestroyObjectDict = new Dictionary<string, GameObject>();

		public static void AddDontDestroyObject(GameObject GO)
		{
			dontDestroyObjectDict[GO.name] = GO;
		}

		public static GameObject FindDontDestroyObject(string name)
		{
			if (dontDestroyObjectDict.ContainsKey(name))
				return dontDestroyObjectDict[name];

			//如果是加载生成的游戏物体名称会增加后缀"(Clone)"
			string cloneName = name + "(Clone)";
			if (dontDestroyObjectDict.ContainsKey(cloneName))
				return dontDestroyObjectDict[cloneName];

			return null;
		}

		/***********************************场景Camera***************************************************/
		/// <summary>
		/// Camera.main获取相机会遍历场景所有物体，所以缓存下来加快速度
		/// </summary>
		/// <returns></returns>
		private static Camera mainCamera;
		public static Camera GetMainCamera()
		{
			if (mainCamera == null)
			{
				mainCamera = Camera.main;
			}
			return mainCamera;
		}

		/// <summary>
		/// 场景中UI相机
		/// </summary>
		private static Camera UICamera;
		public static Camera GetUICamera()
		{
			if (UICamera == null)
			{
				GameObject GO = GameObject.FindGameObjectWithTag("UICamera");
				if (GO != null)
					UICamera = GO.GetComponent<Camera>();
			}
			return UICamera;
		}

		/***********************************颜色列表******************************************************/
		private static List<Color> colorList;
		public  static List<Color> ColorList
		{
			get
			{
				if (colorList == null)
				{
					Color temp;
					colorList = new List<Color>();
					foreach (string htmlColor in FWConfig.htmlColorList)
					{
						if (ColorUtility.TryParseHtmlString(htmlColor, out temp))
						{
							colorList.Add(temp);
						}
					}
				}
				return colorList;
			}
		}
	}

}

